#include "prime.hh"

using namespace std;

int main(int ac, char **av)
{
    if (ac != 6)
    {
        cerr << "USAGE: ./find_prime <module_name> <number1> <number2> <number3> <number4>" << endl;
        return (1);
    }

    Prime module1(av[1]);
    Prime module2(av[1]);
    Prime module3(av[1]);
    Prime module4(av[1]);

    int val1 = atoi(av[2]);
    int val2 = atoi(av[3]);
    int val3 = atoi(av[4]);
    int val4 = atoi(av[5]);

    module1.SetValue(val1);
    module2.SetValue(val2);
    module3.SetValue(val3);
    module4.SetValue(val4);

    module1.ExecuteDistributed();
    usleep(1000000);
    module2.ExecuteDistributed();
    usleep(1000000);
    module3.ExecuteDistributed();
    usleep(1000000);
    module4.ExecuteDistributed();

    while (module1.IsReady() != true || module2.IsReady() != true || module3.IsReady() != true || module4.IsReady() != true)
        usleep(1000);

    cout << "The " << val1 << "-eme prime number is: " << module1.GetResult() << endl;
    cout << "The " << val2 << "-eme prime number is: " << module2.GetResult() << endl;
    cout << "The " << val3 << "-eme prime number is: " << module3.GetResult() << endl;
    cout << "The " << val4 << "-eme prime number is: " << module4.GetResult() << endl;

    return(0);
}
